import 'package:app_30/res/colors.dart';
import 'package:app_30/res/dimens.dart';
import 'package:app_30/res/styles.dart';
import 'package:app_30/widgets/load_image.dart';
import 'package:app_30/widgets/my_app_bar.dart';
import 'package:app_30/widgets/my_scroll_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class SharePage extends StatefulWidget {
  const SharePage({Key? key}) : super(key: key);

  @override
  State<SharePage> createState() => _SharePageState();
}

class _SharePageState extends State<SharePage> {
  @override
  Widget build(BuildContext context) {
    final List<Widget> children = [
      const Text.rich(
        TextSpan(
          style: TextStyles.textSize16,
          children: [
            WidgetSpan(
              child: LoadAssetImage(
                'tuiguang',
                height: Dimens.gap_dp16,
                width: Dimens.gap_dp16,
              ),
            ),
            TextSpan(
              text: ' 标志的资讯，赚取佣金～',
            ),
          ],
        ),
      ),
    ];

    return Scaffold(
        appBar: const MyAppBar(
          isBack: false,
          centerTitle: '分享',
        ),
        body: MyScrollView(
          children: [
            Container(
              color: Colors.white,
              child: Padding(
                  padding: EdgeInsets.all(15),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Row(
                        mainAxisSize: MainAxisSize.max,
                        children: [
                          Image.asset(
                            "assets/image/tuiguang.png",
                            width: 13,
                            height: 13,
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 5),
                            child: Text(
                              "推广方式A：推荐别人访问你的推广连接",
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  fontSize: 16, color: Colors.black54),
                            ),
                          )
                        ],
                      ),
                      buildPadding(),
                      Row(mainAxisSize: MainAxisSize.max, children: [
                        Text(
                          "1.手动阀手动阀\n1.手动阀手动阀\n1.手动阀手动阀\n1.手动阀手动阀",
                          textAlign: TextAlign.left,
                          style: TextStyle(fontSize: 14, color: Colors.black54),
                        )
                      ]),
                      buildPadding(),
                      Text(
                        ".我的推广积分：61分，（够118积分，可以获取1个月VIP）",
                        textAlign: TextAlign.left,
                        style: TextStyle(fontSize: 14, color: Colors.orange),
                      ),
                      SizedBox(
                        height: 6,
                      ),
                      Container(
                          padding: EdgeInsets.all(5),
                          color: Color(0x551CC6B9),
                          child: Text(
                            "新出一个火爆全网的好项目，一天几十到几百，不管你从事什么工作都不影响你多这一份收入，无需投入，操作难度低，不管是宝妈，还是学生，还是待业人士，工薪阶层，都可以做，有手机就行：https://t0vtlsl8.cn/index.php?id=will111推荐人：will111",
                            textAlign: TextAlign.left,
                            style: TextStyle(fontSize: 14, color: Colors.grey),
                          )),
                      SizedBox(
                        height: 10,
                      ),
                      Row(mainAxisSize: MainAxisSize.max, children: [
                        Expanded(
                            child: SizedBox(
                          height: 30,
                          child: TextButton(
                            child: Text("开通vip"),
                            //添加一个点击事件
                            onPressed: () {},
                            //设置按钮是否自动获取焦点
                            autofocus: true,
                            //定义一下文本样式
                            style: buildButtonStyle(),
                          ),
                        )),
                        SizedBox(
                          width: 10,
                        ),
                        Expanded(
                            child: // use Spacer
                                SizedBox(
                          height: 30,
                          child: TextButton(
                            child: Text("免费申请vip"),
                            //添加一个点击事件
                            onPressed: () {},
                            //设置按钮是否自动获取焦点
                            autofocus: true,
                            //定义一下文本样式
                            style: buildButtonStyle(),
                          ),
                        )),
                        SizedBox(
                          width: 10,
                        ),
                        Expanded(
                            child: // use Spacer
                                SizedBox(
                          height: 30,
                          child: TextButton(
                            child: Text("免费申请vip"),
                            //添加一个点击事件
                            onPressed: () {},
                            //设置按钮是否自动获取焦点
                            autofocus: true,
                            //定义一下文本样式
                            style: buildButtonStyle(),
                          ),
                        ))
                      ]),
                      Padding(
                        padding: EdgeInsets.only(top: 10, bottom: 10),
                        child: SizedBox(
                          width: double.infinity,
                          height: 10,
                          child: Container(
                            color: Colors.black12,
                          ),
                        ),
                      ),
                      Row(
                        mainAxisSize: MainAxisSize.max,
                        children: [
                          Image.asset(
                            "assets/image/fenxiang2.png",
                            width: 13,
                            height: 13,
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 5),
                            child: Text(
                              "推广方式B：邀请别人成功注册",
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  fontSize: 16, color: Colors.black54),
                            ),
                          )
                        ],
                      ),
                      buildPadding(),
                      Row(mainAxisSize: MainAxisSize.max, children: [
                        Text(
                          "1.手动阀手动阀\n1.手动阀手动阀\n1.手动阀手动阀\n1.手动阀手动阀\n1.手动阀手动阀\n1.手动阀手动阀\n1.手动阀手动阀",
                          textAlign: TextAlign.left,
                          style: TextStyle(fontSize: 14, color: Colors.black54),
                        )
                      ]),
                      buildPadding(),
                      Text(
                        ".我的注册人数：1人，（够28积分，可以获取终身VIP）",
                        textAlign: TextAlign.left,
                        style: TextStyle(fontSize: 14, color: Colors.orange),
                      ),
                      SizedBox(
                        height: 6,
                      ),
                      Row(mainAxisSize: MainAxisSize.max, children: [
                        Expanded(
                            child: SizedBox(
                          height: 30,
                          child: TextButton(
                            child: Text("查询注册人数"),
                            //添加一个点击事件
                            onPressed: () {},
                            //设置按钮是否自动获取焦点
                            autofocus: true,
                            //定义一下文本样式
                            style: buildButtonStyle(),
                          ),
                        )),
                        SizedBox(
                          width: 10,
                        ),
                        Expanded(
                            child: // use Spacer
                                SizedBox(
                          height: 30,
                          child: TextButton(
                            child: Text("一件分享"),
                            //添加一个点击事件
                            onPressed: () {},
                            //设置按钮是否自动获取焦点
                            autofocus: true,
                            //定义一下文本样式
                            style: buildButtonStyle(),
                          ),
                        ))
                      ])
                    ],
                  )),
            )
          ],
        ));
  }

  Padding buildPadding() {
    return Padding(
      padding: EdgeInsets.only(top: 10, bottom: 10),
      child: SizedBox(
        width: double.infinity,
        height: 1,
        child: Container(
          color: Colors.grey,
        ),
      ),
    );
  }

  ButtonStyle buildButtonStyle() {
    return ButtonStyle(
      //定义文本的样式 这里设置的颜色是不起作用的
      textStyle: MaterialStateProperty.all(
          TextStyle(fontSize: 15, color: Colours.app_main)),
      //设置按钮上字体与图标的颜色
      //foregroundColor: MaterialStateProperty.all(Colors.deepPurple),
      //更优美的方式来设置
      foregroundColor: MaterialStateProperty.resolveWith(
        (states) {
          if (states.contains(MaterialState.focused) &&
              !states.contains(MaterialState.pressed)) {
            //获取焦点时的颜色
            return Colors.white;
          } else if (states.contains(MaterialState.pressed)) {
            //按下时的颜色
            return Colors.white70;
          }
          //默认状态使用灰色
          return Colors.white;
        },
      ),
      //背景颜色
      backgroundColor: MaterialStateProperty.resolveWith((states) {
        //设置按下时的背景颜色
        if (states.contains(MaterialState.pressed)) {
          return Colours.dark_app_main;
        }
        //默认不使用背景颜色
        return Colours.app_main;
      }),
      //设置水波纹颜色
      overlayColor: MaterialStateProperty.all(Colours.app_main),
      //设置阴影  不适用于这里的TextButton
      elevation: MaterialStateProperty.all(0),
      //设置按钮内边距
      padding: MaterialStateProperty.all(EdgeInsets.zero),
      //设置按钮的大小
      // minimumSize: MaterialStateProperty.all(Size(double.infinity, 20)),
      //设置边框
      // side: MaterialStateProperty.all(BorderSide(color: Colors.grey, width: 1)),
      //外边框装饰 会覆盖 side 配置的样式
      // shape: MaterialStateProperty.all(StadiumBorder()),
    );
  }
}
